package cn.edu.zjut.app;

import cn.edu.zjut.bean.IItem;
import cn.edu.zjut.bean.IItemOrder;
import cn.edu.zjut.bean.ShoppingCart;
import cn.edu.zjut.event.EmailEvent;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;

import java.util.*;

/**
 * @author XiaoFeng
 * @version 1.0
 * @Description Create by 2021/12/3 14:30
 */

public class SpringEnvTest {
    public static void main(String[] args) {
//        ApplicationContext ctx = new ClassPathXmlApplicationContext(
//                "applicationContext.xml");
//        ShoppingCart shoppingCart = (ShoppingCart) ctx.getBean("shoppingcart");
//        List itemOrderList = shoppingCart.getItemsOrdered();
//        Map itemOrderMap = shoppingCart.getItemOrdered();
//        IItemOrder itemorder2 = (IItemOrder)ctx.getBean("itemorder2");
        /*
        XmlBeanFactory创建BeanFactory实例
         */
//        FileSystemResource isr= new FileSystemResource("src/main/resources/applicationContext.xml");
//        XmlBeanFactory factory = new XmlBeanFactory(res);
//        IItemOrder itemOrder3 = (IItemOrder) factory.getBean("itemorder3");
        /*
        ClassPathResource
         */
//        ClassPathResource res = new ClassPathResource("applicationContext.xml");
//        XmlBeanFactory factory = new XmlBeanFactory(res);
//        IItemOrder itemOrder3 = (IItemOrder) factory.getBean("itemorder3");

//        ApplicationContext ctx = new ClassPathXmlApplicationContext(
//                "applicationContext.xml");
//        IItemOrder itemorder3 = (IItemOrder) ctx.getBean("itemorder3");

//        ApplicationContext ctx =
//                new FileSystemXmlApplicationContext("src/main/resources/applicationContext.xml");
//        IItemOrder itemorder3 = (IItemOrder) ctx.getBean("itemorder3");
//        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//        Object[] objects = new Object[]{"HelloWorld",new Date()};
//        String message = ctx.getMessage("HelloWorld",objects,Locale.US);
//        System.out.println(message);
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        EmailEvent ele = new EmailEvent("hello","spring_test@zjut.edu.cn","this is a test");
        ctx.publishEvent(ele);

    }

}
